<?php
/* @var $this FuncionarioController */
/* @var $model Funcionario */

$this->pageTitle=Yii::app()->name . ' - Colaboradores';

$this->breadcrumbs=array(
		'Colaboradores'=>array('index'),
		'Gerenciar',
);

$this->menu=array(
		array('label'=>'Cadastrar Colaborador', 'url'=>array('create'), 'visible'=> Yii::app() -> session['user_type'] == 'Administrador'),
);

Yii::app()->clientScript->registerScript('search', "
		$('.search-button').click(function(){
		$('.search-form').toggle();
		return false;
});
		$('.search-form form').submit(function(){
		$('#funcionario-grid').yiiGridView('update', {
		data: $(this).serialize()
});
		return false;
});
		");
?>

<h2 align="center">Colaboradores</h2>


<div class="search-form" style="display: none">
	<?php 
	$this->renderPartial('_search',array(
			'model'=>$model,
)); ?>
</div>
<!-- search-form -->
<?php $idAtual = Yii::app() -> session['user_type'] == 'Administrador'? 0 : 1; ?>
<?php $this->widget('zii.widgets.grid.CGridView',array(
		'id'=>'funcionario-grid',
		'pager' => array('cssFile' => Yii::app()->baseUrl . '/css/gridview.css',
				'firstPageLabel'=>'Início',
				'lastPageLabel'=>'Fim',
				'nextPageLabel'=>'Próximo >',
				'header'=>'Página Atual:',
				'prevPageLabel'=>'< Anterior',),
		'cssFile' => Yii::app()->baseUrl . '/css/gridview.css',
		'htmlOptions'=>array('class'=>'grid-view rounded'),
		'summaryText' => 'Mostrando {start}-{end} de {count} registro(s).',
		'dataProvider'=>$model->search(),
		'columns'=>array(
				array('name'=>'search_nome',
						'value'=>'$data->pessoa->nome',
					),

				array('name'=>'tipo',
						'filter'=> array('Funcionario' => 'Funcionario', 'Voluntario' => 'Voluntario'),),
				
				array(
						'class'=>'CLinkColumn',
						'header'=>'Email',
						'labelExpression'=>'$data->pessoa->email',
						'urlExpression'=>'"mailto:".$data->pessoa->email',
				),
				array(
						'header' => 'Ações',
						'class' => 'CButtonColumn',
						'htmlOptions' =>array('width'=>'60px'),
						'viewButtonImageUrl' => Yii::app()->baseUrl . '/css/' . 'gr-view.png',
						'updateButtonImageUrl' => Yii::app()->baseUrl . '/css/' . 'gr-update.png',
						'deleteButtonImageUrl' => Yii::app()->baseUrl . '/css/' . 'gr-delete.png',
						'template' => '{view} {update} {delete}',
						'deleteConfirmation'=>"js:'Deseja Realmente excluir este Colaborador?'",
						'buttons' => array (
								'view' => array (
										'visible'=> '$data->id != 1',
								),
								'update' => array (
										'visible'=> '$data->id != 1 && ' . $idAtual .' == 0 && $data->id != '. Yii::app() -> session['idAtual'],
								),
								'delete' => array (
										'visible'=> '$data->id != 1 && '. $idAtual .' == 0 && $data->id != '. Yii::app() -> session['idAtual'],
								),
						)
				),
		),
		'emptyText' => 'Nenhum Colaborador cadastrado',
)); ?>
